package com.kun.controller;

import com.kun.req.MemberLoginReq;
import com.kun.req.MemberRegisterReq;
import com.kun.req.MemberSendCodeReq;
import com.kun.resp.CommonResp;
import com.kun.resp.MemberLoginResp;
import com.kun.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @className: TestController
 * @Description: ...
 * @author: kunkun
 * @date: 2025/7/8 15:27
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @RequestMapping("/count")
    public CommonResp<Integer> count(){
        return new CommonResp<Integer>(memberService.count());
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid MemberRegisterReq registerReq){
        return new CommonResp<Long>(memberService.register(registerReq));
    }

    @PostMapping("/send-code")
    public CommonResp<String> sendCode(@Valid @RequestBody MemberSendCodeReq memberSendCodeReq){
        memberService.sendCode(memberSendCodeReq);
        return new CommonResp<>("短信发送成功");
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq loginReq){
        return new CommonResp<>(memberService.login(loginReq));
    }


}
